layui.use(['table', 'laytpl', 'layer', 'upload'], function() {
	var $ = layui.$;
	var table = layui.table;
	var type;
	var url = location.href;
	var upload = layui.upload;
	var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
	var id = paraString[0].substring(paraString[0].indexOf("=") + 1, paraString[0].length);
	var type = paraString[1].substring(paraString[1].indexOf("=") + 1, paraString[1].length);
	if(type == "edit") {
		$(".upbtn").css("display","block");
		lunbomsg();
		noreadonly();
		
	} else if(type == "detail") {
		readonly();
		lunbomsg();
	}else if(type == "add"){
		$(".upbtn").css("display","block");
	}
	function lunbomsg() {
		$.ajax({
			type: "post",
			url: "/lunbo/msg",
			async: true,
			data: {
				id: id
			},
			success: function(data) {
				var ret = JSON.parse(data);
				$("#flowerimg")[0].src = ret.img64;
				$(".imgtitle").val(ret.title);
			}
		});
	}
	uploadimg();

	function uploadimg() {
		var uploadInst = upload.render({
			elem: '#fileBtn',
			url: '/upload/img',
			accept: 'images',
			before: function(obj) {
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result) {
					$('#flowerimg').attr('src', result); //图片链接（base64）
				});
			},
			done: function(res) {},
			auto: 'false',
			bindAction: 'fileUploadBtn',
			error: function() {
				//请求异常回调
			}
		});

	}

	function readonly() {
		$(".imgtitle").attr("readonly", "readonly");
	}

	function noreadonly() {
		$(".imgtitle").removeAttr("readonly");
	}
});